#include "stepmotor.h"
#include "delay.h"

void StepMotorPinInit(void)
{
	/*
	PA7---A
	PA6---A_
	PA5---B
	PA4---B_
	*/
	
	RCC->APB2ENR |=1<<2;
	
	GPIOA->CRL &=~(0xFFFF<<16);
	GPIOA->CRL |= (0x3333<<16);
	
	STOP;
}

//全程800次节拍，平均分成10分，每一份80次节拍
//mode: LEFT RIGHT
void StepMotorContorl(uint8_t mode,uint8_t num)
{
	uint16_t i,j;
	switch (mode)
	{
		case 0: STOP ; break;
		case 1:
				//12341234.....
				for(i=0;i<num*80;i++)
					{ 
						switch(i%4) 
						{
							case 0:STE_1;break;
							case 1:STE_2;break;
							case 2:STE_3;break;
							case 3:STE_4;break;
						}
						Delayms(1);
					}
				break;
		case 2:
				//43214321.....
				for(j=0;j<num*80;j++)
				{ 
					switch(j%4) 
					{
						case 0:STE_4;break;
						case 1:STE_3;break;
						case 2:STE_2;break;
						case 3:STE_1;break;
					}
					Delayms(1);
				}
				break;
	}
	STOP;
}

